<template>
  <div>
    <div class="center">
        <el-form  label-width="80px" >
          <div class="input">
            <el-form-item label="账号">
            <el-input v-model="username" ></el-input>
            </el-form-item>
          </div>
          <div class="input">
            <el-form-item label="密码">
              <el-input v-model="password" ></el-input>
            </el-form-item>
          </div>
          <el-button @click="login" class="button" >登录</el-button>
      </el-form>
  </div>
    
</div>
</template>

<script>
  export default {
    data() {
      return {
        username:'',
        password:'',
      }
    },
    created() {
      
    },
    methods: {
      async login(){
        let res = await this.$http.post('/user/signin', {
          username: this.username,
          password: this.password
        })
        console.log(res);
        if(res.errcode == 0){
          // res.data
          this.$store.commit('setUser', res.data)
          console.log(1)
          console.log(this.$store.state.user);
          // 存到硬盘，第一个参数是属性，获取的时候需要，第二个就是他的值
          localStorage.setItem('token', res.data.token)
          this.$router.push('/')
        }

        res = await this.$http.get('/brand/select')
        console.log(res)
      }
    },
  }
</script>
<style scoped>
  .center{
    position: absolute;
    width: 400px;
    height: 230px;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    border: 1px solid #EEEEEE;
  }
  .input{
    margin: 20px;
    width: auto;
  }
  .button{
    margin-left: 100px;
    background: #008080;
    color: white;
  }
</style>